package org.hfy.collections.helper;

import org.hfy.Constants;
import org.hfy.StringUtils;

/**
 * @Description:
 * @Author: Takagi
 * @date: 2023/4/26
 */
public class Action {
    public Symbol actionType;
    public Symbol stateNo;
    public Symbol productionNo;
    public SymbolString productionNumbers;
    public Production production;
    public boolean accept = false;

    public Symbol getReducedSymbol() {
        return this.production.left;
    }

    @Override
    public String toString() {
        if (this.accept) {
            return Constants.ACCEPT;
        }
        if (Constants.isShiftAction(this.actionType)) {
            return String.format("s%s", StringUtils.extractNumbers(this.stateNo));
        } else {
            return String.format("r%s", StringUtils.extractNumbers(this.productionNo));
        }
    }
}
